<?php 
namespace app\exam\controller;
use think\Db;
class Category extends Base{

	public function read(){
		$data=Db::table('type_name')->select();
		// print_r($data);die;
		return json_encode(['code'=>10000,'msg'=>'查询成功','data'=>$data]);

	}

    public function  verify(){
        $data=input();
        $model=model('user');
        $res=$model->getone(['login_flag'=>$data['login_flag']]);
        if($res){
            if(strpos($res['important_vip'], $data['type_id'])!==false){

                    return  json_encode(['code'=>10000,'msg'=>'可以查询']);

//                    return  json_encode(['code'=>10001,'msg'=>'暂无数据']);



            }else{
                return json_encode(['code'=>10001,'msg'=>'无权限']);
            }
        }else{
            return json_encode(['code'=>10001,'msg'=>'请注册']);
        }


    }




	public function  search(){
	    $data=input();
        $model=model('user');
        if(empty($data['keyword'])){
            return  json_encode(['code'=>10001,'msg'=>'关键字不能为空']);
        }
        $res=$model->getone(['login_flag'=>$data['login_flag']]);
        if($res){
            if(strpos($res['important_vip'], $data['type_id'])!==false){
                $where['s_question']=['like','%'.$data['keyword'].'%'];
                $where['type_num']=['=',$data['type_id']];
               $result=Db::table('questiones')->where($where)->select();
               $arr=[];
                foreach ($result as $k=>&$v){
                    $arr[]=[
                        'question_id'=>$v['question_id'],
                        's_question'=>$v['s_question'],
                        'c_id'=>$v['comprehensive_id']
                    ];
                }

//               print_r($result);
                if($arr){
                    return  json_encode(['code'=>10000,'msg'=>'查询成功','data'=>$arr]);
                }else{
                    return  json_encode(['code'=>10001,'msg'=>'暂无数据']);
                }


            }else{
                return json_encode(['code'=>10001,'msg'=>'无权限']);
            }
        }else{
            return json_encode(['code'=>10001,'msg'=>'请注册']);
        }


    }

    public function  detail(){
        $data=input();
        if($data['c_id']==0){
            $result=Db::table('questiones')->where(['question_id'=>$data['question_id']])->find();
            if($result){
                if($result['has_img']==1){
                    $str1='';
                    $repty=Db::table('questionimg')->where(['question_id'=>$data['question_id']])->select();
                    foreach ($repty as $k => $v6) {
                        $str1.=$v6['img_url'].',';
                    }

                    $result['img']=$str1;
                }else{
                    $result['img']='';
                }
                $arr=[
                    'desc'=>'',
                    'c_id'=>0,
                    's_answer'=>$result['s_answer'],
                    's_question'=>$result['s_question'],
                    's_choose_answer'=>$result['s_choose_answer'],
                    'question_id'=>$result['question_id'],
                    'question_type'=>$result['question_type'],
                    'img'=>$result['img']
                ];
               // print_r($arr);
                return json_encode(['code'=>10000,'msg'=>'查询成功','data'=>$arr]);
            }else{
                return json_encode(['code'=>10001,'msg'=>'暂无数据']);
            }
        }else{
            $rept=Db::table('descquestion')->where(['c_id'=>$data['c_id']])->find();
            $result=Db::table('questiones')->where(['question_id'=>$data['question_id']])->find();
            if($rept&&$result){
                if($result['has_img']==1){
                    $str1='';
                    $repty=Db::table('questionimg')->where(['question_id'=>$data['question_id']])->select();
                    foreach ($repty as $k => $v6) {
                        $str1.=$v6['img_url'].',';
                    }

                    $result['img']=$str1;
                }else{
                    $result['img']='';
                }
                $arr=[
                    'desc'=>$rept['c_decs'],
                    'c_id'=>$rept['c_id'],
                    's_answer'=>$result['s_answer'],
                    's_question'=>$result['s_question'],
                    's_choose_answer'=>$result['s_choose_answer'],
                    'question_id'=>$result['question_id'],
                    'question_type'=>$result['question_type'],
                    'img'=>$result['img']
                ];
                //print_r($arr);
                return json_encode(['code'=>10000,'msg'=>'查询成功','data'=>$arr]);
            }else{
                return json_encode(['code'=>10001,'msg'=>'暂无数据']);
            }
        }

    }


	public function test(){
		 echo 'aaaatest';
//        $ret=Db::table('descquestion')->where('c_decs','like','%'.$data['keyword'].'%')->field('c_id,c_decs')->select();
	}





}
















 ?>